<?
function kirim(){
	global $inp_par,$inp,$cdivisi_kode;
        $sql = "select * from m_proyek where id_proyek='$inp[id_proyek]' and divisi_kode='$cdivisi_kode'";
	$res = dbresult($sql);
	$r = pg_fetch_array($res);
	echo "<form name=account action=\"?".var_kirim($inp_par)."\" method=post>
			<input type=hidden name=inp[id_proyek] value='$r[id_proyek]'>
                        <input type=hidden name=inp[nama_proyek] value='$r[nama_proyek]'>
			</form>";
	echo "<script>Send();</script>";
}

function lihat(){
	global $inp_par,$inp,$cdivisi_kode;
//        ctk_r($inp_par);

            $sqlwil = "select * from tbl_divisi where divisi_name!='' and divisi_kode='$cdivisi_kode'";
            $result = dbresult($sqlwil);
            $rs = pg_fetch_array($result);
            $txtout.="<table width=\"98%\" height=\"35\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
		<tr>
		<td height=\"5\" colspan=\"2\"><img src=\"../img/0.gif\" width=\"1\" height=\"10\"></td>
		</tr>
		<tr>
		<td width=\"15\" background=\"../img/bg-jdl-ppn.gif\">&nbsp;</td>
		<td height=\"25\" background=\"../img/bg-jdl-ppn.gif\"><img src=\"../img/jdl-proyek1.gif\" height=\"25\"></td>
		</tr>
		</table>

		<form name=\"form2\" method=\"post\" action=\"?".var_kirim($inp_par)."\">
		<table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"hitam\">
		<tr>
                <td width='29%' align='left'><strong>&nbsp;".strtoupper($rs[divisi_name])."</strong></td>
		<td width='42%' align='center' class=\"tbltagihan\">Search :&nbsp;<input name=\"inp_par[kata]\" type=\"text\" class=\"form1\" size=\"30\" value=\"$inp_par[kata]\">&nbsp;<input type=\"submit\" name=\"Submit\" value=\"GO &raquo;\" class=\"tombolgo\"></td>
		<td width='29%'>&nbsp;</td>
		</tr>
		</table>
                <table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
		<tr>
		<td><a href=\"?".var_kirim($inp_par,"mode")."\" class=\"menuppnaktif\">DAFTAR PROYEK</a></td>
		<td width=\"2\"><img src=\"../img/0.gif\" width=\"2\" height=\"1\"></td>
		<td><a href=\"?inp_par[mode]=add".var_kirim($inp_par)."\" class=\"menuppn\">INPUT PROYEK</a></td>
		</tr>
		</table>
		
		
		<table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"C6E6FF\" class=\"tabel1\">
		<tr class=\"tbltagihan\">
		<td width=\"30\"> <div align=\"center\">No</div></td>
		<td width=\"100\">No Proyek</td>
		<td>Nama Proyek</td>
		</tr>";
//        $divisi_kode = $inp_par[divisi_kode] == ""? " and divisi_kode='$cdivisi_kode'":" and divisi_kode='$inp_par[divisi_kode]'";
        if ($inp_par[kata]!=""){
            $search=" (lower(id_proyek) like '%".strtolower($inp_par[kata])."%' or lower(nama_proyek) like '%".strtolower($inp_par[kata])."%')";
        }else{
            $search="";
        }
        $sql="select * from m_proyek where true $search and divisi_kode='$cdivisi_kode' order by nama_proyek asc";
//        echo $sql;
//	$sql="select * from tbl_fp_daftar_customer $search order by nama_customer asc";
	$arr_tabel=definisi_halaman($sql);
	$result=$arr_tabel["res_sql"];
	$i=1+$inp_par[awalan]*$inp_par[jumlah_per_hal];
	while($r=pg_fetch_array($result)){
		$warna=$warna=="#E3F1FC"?"#F4FAFF":"#E3F1FC";
		$txtout.="<tr onmouseover=\"this.style.backgroundColor='#FDFFDD';\" style=\"background-color: $warna;\" onmouseout=\"this.style.backgroundColor='$warna';\">
			<td><div align=\"center\"><input type=radio name=inp[id_proyek] value='$r[id_proyek]'></div></td>
			<td>$r[id_proyek]</td>
			<td>$r[nama_proyek]</td>
			</tr>";
		$i++;
	}

	$txtout.="</table>
		</table>
		<table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"tbltagihan\">
		<tr>
		<td>&nbsp;<input type=\"submit\" name=\"inp[aksi]\" value=\"Ok &raquo;\" class=\"tomboladd\">
		<input type=\"button\" name=\"Submit2222222222\" value=\"Cancel &raquo;\" class=\"tomboladd\" onClick=\"window.close();\">
		</td>
		<td>
		$arr_tabel[tabel_halaman]
		</td>
		</tr>
		</table>
		</form>";
	return $txtout;
}

function form(){
	global $inp_par, $inp, $permisi, $sql_tambahan, $kode;

	//Start Load Data//
        $id_proyek = kdauto("m_proyek","PR");
	if ($inp_par[mode]=="edit"){
		$sql2="select * from m_proyek where id_proyek='$inp_par[id_proyek]'";
		$result2 = dbresult($sql2);//cho $sql2;
		$r = pg_fetch_array($result2,0);
	}

        //Start Check Validasi//
        $r[id_proyek] = $r[id_proyek] == ""? $id_proyek: $r[id_proyek];
        $r[nama_proyek] = $inp[nama_proyek] == ""? $r[nama_proyek]: $inp[nama_proyek];
        generate_rule("is_isi","inp[id_proyek]","Anda Harus Mengisi ID Proyek");
	generate_rule("is_isi","inp[nama_proyek]","Anda Harus Mengisi Nama Proyek");

        $txtout=generate_validasi();
	//End Check Validasi//

	//End Load Data//
	$txtout.="<table width=\"98%\" height=\"35\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
		<tr>
		<td height=\"5\" colspan=\"2\"><img src=\"../img/0.gif\" width=\"1\" height=\"10\"></td>
		</tr>
		<tr>
		<td width=\"15\" background=\"../img/bg-jdl-ppn.gif\">&nbsp;</td>
		<td height=\"25\" background=\"../img/bg-jdl-ppn.gif\"><img src=\"../img/jdl-proyek1.gif\" height=\"25\"></td>
		</tr>
		</table>
                <table width=\"98%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">
		<tr>
		<td><a href=\"?".var_kirim($inp_par,"mode")."\" class=\"menuppn\">DAFTAR PROYEK</a></td>
		<td width=\"2\"><img src=\"../img/0.gif\" width=\"2\" height=\"1\"></td>
		<td><a href=\"?inp_par[mode]=add".var_kirim($inp_par)."\" class=\"menuppnaktif\">INPUT PROYEK</a></td>
		</tr>
		</table>
                <form name=form1 method=\"post\" action=\"?".var_kirim($inp_par)."\" onSubmit=\"return validasi(document.form1);\">
		<table width=98% border=0 align=center cellpadding=3 cellspacing=1 bgcolor=\"C6E6FF\" class=tabel1>
		<tr class=\"tbltagihan\">
		<td colspan=\"3\">Form Input Daftar Proyek</td>
		</tr>
		<tr bgcolor=\"#FFFFFF\">
		<td width=30> <div align=center>1.</div></td>
		<td width=130 bgcolor=\"#FFFFFF\">KODE PROYEK</td>
		<td bgcolor=\"#FFFFFF\"><input name=\"inp[id_proyek]\" type=\"text\" class=\"form2\" size=\"10\" value=\"".trim($r["id_proyek"])."\" maxlength=10 disabled>
                    <input name=\"inp[id_proyekH]\" type=\"hidden\" class=\"form2\" size=\"15\" value=\"".trim($r["id_proyek"])."\" maxlength=10></td>
		</tr>
		<tr bgcolor=\"#FFFFFF\">
		<td width=30> <div align=center>2.</div></td>
		<td width=130 bgcolor=\"#FFFFFF\">NAMA PROYEK</td>
		<td><input onkeyup=\"ToUpper(this)\" name=\"inp[nama_proyek]\" type=\"text\" class=\"form2\" size=\"60\" value=\"".trim($r["nama_proyek"])."\"></td>
		</tr>
		";

	$txtout.="<tr bgcolor=\"#FFFFFF\">
		<td colspan=\"3\"> <div align=\"center\">
		<input type=\"submit\" name=\"inp[aksi]\" value=\"Save &raquo;\" class=\"tombolgo\">
		<input type=\"button\" name=\"Submit2222222222\" value=\"Cancel &raquo;\" class=\"tombolgo\" onClick=\"javascript:history.back()\">
		</div></td>
		</tr>
		</table>
		</form>";
	return $txtout;

}

function tambah(){
	global $inp,$inp_par,$inp_cook,$cnama,$cdivisi_kode;
	$sql="insert into m_proyek (id_proyek,nama_proyek,entry_date,entry_by,update_date,update_by,entry_ip,update_ip,divisi_kode)values('".trim($inp[id_proyekH])."','".trim($inp[nama_proyek])."','".e_getDateNow()."','".$cnama."','".e_getDateNow()."','".$cnama."','".e_getIpAddr()."','".e_getIpAddr()."','".$cdivisi_kode."')";
	dbresult($sql);
	echo "<script>window.location='?".var_kirim($inp_par,"mode")."';</script>";

}

function generate_form($inp_par){
	global $inp;
	switch ($inp_par[mode]) {
		case "add":
                        $txtout.=$inp[aksi]==""?form():tambah();
		break;
		case "lihat":
			$txtout.=$inp[aksi]==""?lihat():kirim();
		break;
		default:
                        $txtout.=$inp[aksi]==""?lihat():kirim();
		break;
	}
	return $txtout;
}
?>
